package com.cfs.svcimpl.sys;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.cfs.dao.sys.CascDao;
import com.cfs.svc.sys.CascadeService;
import com.cfs.po.sys.Dict;
import com.cfs.po.sys.LongId;


public class CascadeServiceImpl implements CascadeService {

	private CascDao dao;
	
	public void setDao(CascDao dao){
		this.dao = dao;
	}

	@Override
	public Dict getByNamePk(String name, Integer pk) {
//		System.out.println("AA:" + name + " pk:" + pk);
		return dao.getByNamePk(name, pk);
	}

	@Override
	public Dict[] getByNamePks(String name, LongId pks) {
//		System.out.println("AA:" + name + " pk:" + pks.getIds().length);
		return dao.getByNamePks(name, pks.getIds());
	}


	@Override
	public int addDict(Dict d) {
//		System.out.println("name:" + d.getName() + " size" + d.getKvs());
		
		return dao.add(d);
	}

	@Override
	public int updateDict(Dict d) {
//		System.out.println("UPDATE: " + d.getName() + " pk:" + d.getPk() + " Items:" + d.getKvs().size());
		return dao.update(d);
	}

	/**
	 * 列出全部级联字典名
	 */
	@Override
	public Dict[] listNames() {
		List<String> sl = dao.listNames();
		Dict[] sa = new Dict[sl.size()];

		int x = 0;
		for(String s : sl){
			Dict d = new Dict();
			d.setName(s);
			sa[x++] = d;
		}

		return sa;
	}

	@Override
	public int deleteByName(String name) {
//		System.out.println("deleteByName: " + name);
		return dao.deleteByName(name);
	}

	@Override
	public int deleteByNamePk(String name, int pk) {
//		System.out.println("deleteByNamePk: " + name + " pk:" + pk);
		return dao.deleteByNamePk(name, pk);
	}

	@Override
	public int deleteByNamePkKey(String name, int pk, int key) {
//		System.out.println("deleteByNameKey: " + name + " PK:" + pk + " EKey:" + key);
		return dao.deleteByNamePkKey(name, pk, key);
	}

	@Override
	public int imp(HttpServletRequest request) {
		String fn = request.getSession().getServletContext().getRealPath("/tmp/区划.xls");
		return dao.impShengShiXian(fn);
	}

//	@Override
//	public BrandDict [] getBrandAndCate() {
//		return dao.getBrandAndCate();
//	}
	
//	/**
//	 * 查询品牌品类级联字典
//	 * @return
//	 */
//	@Override
//	public BrandDict [] getCompeteBrandAndCate(String competeBrand,String competeCategory) {
//		return dao.getCompeteBrandAndCate(competeBrand,competeCategory);
//	}

}
